package com.dream.controller;

import com.dream.pojo.TempInformation;
import com.dream.service.TempInformationService;
import com.dream.service.impl.TempInformationServiceImpl;
import com.dream.utils.PageUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/TempInformationController.do")
public class TempInformationController extends BaseServlet{
        TempInformationService tempInformationService = new TempInformationServiceImpl();

    /**
     * 分页查询
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
        public void list(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
            String stuName = request.getParameter("stuName");//条件1
            String minTemp = request.getParameter("minTemp");//条件2
            String maxTemp = request.getParameter("maxTemp");//条件3
            String pageIndex = request.getParameter("pageIndex");//条件4 当前页码
            if (pageIndex==null||"".equals(pageIndex)){
                pageIndex="1";//默认值
            }
            String pageSize = request.getParameter("pageSize");//条件5 页面大小
            if (pageSize==null||"".equals(pageSize)){
                pageSize="5";//默认值
            }
            //条数
            long totalCount = tempInformationService.totalCount(stuName,minTemp,maxTemp);
            //每页数据
            List<TempInformation> tempInformationList = tempInformationService.list(stuName, minTemp, maxTemp, Long.valueOf(pageIndex), Long.valueOf(pageSize));
            //封装一个分页的工具类
            PageUtil<TempInformation> pageUtil = new PageUtil<TempInformation>(Long.valueOf(pageIndex),Long.valueOf(pageSize),totalCount,tempInformationList);
            //存值转发
            request.setAttribute("pageUtil",pageUtil);
            request.setAttribute("stuName",stuName);//回显搜索条件
            request.setAttribute("minTemp",minTemp);//回显搜索条件
            request.setAttribute("maxTemp",maxTemp);//回显搜索条件
            request.getRequestDispatcher("viewTempRecordInfo.jsp").forward(request,response);
        }
}
